﻿using INTEX.DataBase;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SETUPABON.xaml
    /// </summary>
    public partial class TFOLDER
    {

        public TFOLDER()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_FOLDERS();
            this.DataContext = MV;
            InitializeComponent();
            ART= "D:\\ITXRPRT";
            MV.OnMessage += MV_OnMessage;
        }

        private void MV_OnMessage(object sender, MessageEventArgs e)
        {
            TMV.INFO = e.Info.Details;
        } 
        public override void QueryCommand(object sender, RoutedEventArgs e)
        { 
            try
            { 
                dwData = TBMain.NewRow();
                dwData["MANDANT"] = app.Mandant;
                SResult = TMV.QFALL(dwData);
                MergeData(SResult, true);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        } 
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.DFOLDERS01(dwMaster);

            filter = "ROWNID='" + dwMaster["ROWNID"].ToString() + "'";
            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }
        public override void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TMV.AUTODETECT(TMV.ART);
            base.bgWorker_DoWork(sender, e);
        }
        public override void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            IsBusy = false;
            dwData = TBMain.NewRow();
            dwData["MANDANT"] = app.Mandant;
            SResult =TMV.PageLoad(dwData);
            MergeData(SResult, false);
            base.bgWorker_RunWorkerCompleted(sender, e);
        }

        private void DetectCommand(object sender, RoutedEventArgs e)
        {
            IsBusy = true;
            bgWorker.RunWorkerAsync();
        }
    }
}
